<?php
defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * 订单类  
 */
class Notice extends CI_Controller{
    public function __construct(){
        parent::__construct();
        $this->load->library('request');  //自定义
        $this->load->library('response'); //自定义
        $this->load->library('session'); //公共 
    }

 

    /**
     * [查询消息列表]
     * @return [type] [description]
     */
    public function noticeList(){
        if($this->input->method()=="get"){       
            $reqData = $this->request->getGetData(array("createTime","status","type","pageSize"));
            log_message('info', 'notice/noticeList,data:'.json_encode($reqData)); 

            //1验证登录状态 
            $this->load->model("userModel");
            $retStatus =  $this->userModel->loginStatus($reqData);
            // var_dump($retStatus);exit; 
            if($retStatus['status']){
                $this->response->sendData($retStatus['status']);return;
            }
            $userId = $retStatus['userId'];

            //2查询
            $this->load->model("noticeModel");
            $detail = $this->noticeModel->userNoticeList($userId,$reqData);
            $idStr = '-1';
            foreach ($detail['data'] as $key => $value) {
                $createTime = $value->createTime;
                $detail['data'][$key]->title = str_replace($createTime, '', $value->title);
                $detail['data'][$key]->status = str_replace($createTime, '', $value->status);
                // $idStr .= ','.$value->releaseId;
            } 
            
            $this->response->sendData(0,$detail['data']);return ;    
            
          
        }
        else{
            $this->response->sendData(1001);return ;
        }
    }  

    /**
     * [查询消息子列表]
     * @return [type] [description]
     */
    public function noticeSecondList(){
        if($this->input->method()=="get"){       
            $reqData = $this->request->getGetData(array("releaseId","type"));
            log_message('info', 'notice/noticeSecondList,data:'.json_encode($reqData)); 
            if(!$reqData['releaseId'] ||!$reqData['type']){
                $this->response->sendData(1000);return;                
            }
            //1验证登录状态 
            $this->load->model("userModel");
            $retStatus =  $this->userModel->loginStatus($reqData);
            // var_dump($retStatus);exit; 
            if($retStatus['status']){
                $this->response->sendData($retStatus['status']);return;
            }
            $userId = $retStatus['userId'];

            //2查询 全部消息
            $this->load->model("noticeModel");
            $detail = $this->noticeModel->userSecondNoticeList($userId,$reqData);
            
            
            $this->response->sendData(0,$detail['data']);return ;    
            
          
        }
        else{
            $this->response->sendData(1001);return ;
        }
    }   


    /**
     * [查询未读消息总数]
     * @return [type] [description]
     */
    public function noticeCount(){
        if($this->input->method()=="get"){       
            $reqData = $this->request->getGetData(["status","type"]);
            log_message('info', 'notice/unReadNoticeCount,data:'.json_encode($reqData)); 
            // if(!$reqData['releaseId'] ||!$reqData['type']){
            //     $this->response->sendData(1000);return;                
            // }
            //1验证登录状态 
            $this->load->model("userModel");
            $retStatus =  $this->userModel->loginStatus($reqData);
            // var_dump($retStatus);exit; 
            if($retStatus['status']){
                $this->response->sendData($retStatus['status']);return;
            }
            $userId = $retStatus['userId'];

            //2查询 全部消息
            $this->load->model("noticeModel");
            $detail = $this->noticeModel->userNoticeCount($userId,$reqData);
            
            
            $this->response->sendData(0,'',['noticeCount'=>$detail]);return ;    
            
          
        }
        else{
            $this->response->sendData(1001);return ;
        }
    }   

 
    


}